package com.xja.friend.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xja.friend.entity.Chatuser;
import com.xja.friend.mapper.ChatuserMapper;
import com.xja.friend.service.ChatuserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("chatuserService")
public class ChatuserServiceImpl implements ChatuserService {
    @Resource
    private ChatuserMapper chatuserMapper;


    @Override
    @Transactional(propagation= Propagation.REQUIRED)  //必须保证该方法在一个事务之内运行
    public int insert(Chatuser record) throws Exception {
        return chatuserMapper.insert(record);
    }
    @Override
    public Chatuser seleteByName(String userid) throws Exception {
        return chatuserMapper.seleteByName(userid);
    }

    @Override
    public Page<Chatuser> seletePage(Integer npage, Map map) throws Exception {
        PageHelper.startPage(npage,2);
        return (Page<Chatuser>) chatuserMapper.seleteList(map);
    }

    @Override
    public Chatuser seleteBycid(Integer cid) throws Exception {
        return chatuserMapper.selectByPrimaryKey(cid);
    }


    @Override
    @Transactional(readOnly = true)//只读事务
    public List<Chatuser> findNickName(Integer mineid) throws Exception {
        return chatuserMapper.findNickName(mineid);
    }

    @Override
    @Transactional(readOnly = true)//只读事务
    public Chatuser selectByPrimaryKey(Integer id) throws Exception {
        return chatuserMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int updateByPrimaryKey(Chatuser record) throws Exception {
        return chatuserMapper.updateByPrimaryKey(record);
    }
}
